package com.sep.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sep.common.constant.SepConstant;
import com.sep.common.entity.QueryRequest;
import com.sep.common.utils.SortUtil;
import com.sep.modules.sys.entity.Test;
import com.sep.modules.sys.mapper.TestMapper;
import com.sep.modules.sys.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author 路人甲
 * @create 2021-05-10 13:45
 */
@Slf4j
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService {


    @Override
    public IPage<Test> findTest(Test test, QueryRequest request) {
        try {
            LambdaQueryWrapper<Test> queryWrapper=new LambdaQueryWrapper<>();
            Page<Test> page=new Page<>();
            SortUtil.handlePageSort(request, page, "Id", SepConstant.ORDER_ASC, true);
            return this.page(page,queryWrapper);
        }catch(Exception e){
            log.error("获取信息失败");
            return null;
        }
    }

    @Override
    public void createTest(Test test) {
        test.setCreateTime(new Date());
        this.save(test);
    }

    @Override
    public void deleteTest(String[] ids) {
        List<String> idsList= Arrays.asList(ids);
        this.baseMapper.deleteBatchIds(idsList);
    }

    @Override
    public void updateTest(Test test) {
        this.updateById(test);
    }
}
